package com.yzpc.utils;

import org.apache.commons.lang.StringUtils;

import java.util.HashMap;

public class R extends HashMap<String, Object> {
    /** 状态码 */
    public static final String CODE_TAG = "code";

    /** 返回内容 */
    public static final String MSG_TAG = "msg";

    /** 数据对象 */
    public static final String DATA_TAG = "data";
    //创建一个空的R对象
    public R() {

    }
    public R(int code, String msg) {
        super.put(CODE_TAG, code);
        super.put(MSG_TAG, msg);
    }
    public R(int code, String msg, Object data) {
        super.put(CODE_TAG, code);
        super.put(MSG_TAG, msg);
        if (data != null) {
            super.put(DATA_TAG, data);
        }
    }
    public static R error(String msg, Object data) {
        return new R(500, msg, data);
    }
    public static R success(String msg, Object data) {
        return new R(200, msg, data);
    }
    public static R success() {
        return new R(200, null, null);
    }
    public static R error() {
        return new R(200, null, null);
    }
}
